package com.hgcode.wtboot.web.rest;

import cn.dev33.satoken.stp.SaLoginConfig;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ShenyuResource {

	@GetMapping("/api/index")
	public String index(){
		return "hello world ,shenyu gateway";
	}

	@GetMapping("/api/noauth/login")
	public SaResult login() {
		StpUtil.login(10001, SaLoginConfig
				.setExtra("name", "zhangsan")
				.setExtra("age", 18)
				.setExtra("phone", "13466329314"));
		SaTokenInfo saTokenInfo = StpUtil.getTokenInfo();
		log.info(JSON.toJSONString(saTokenInfo));
		return SaResult.ok("登录成功");

	}
}
